package com.mihu.stmall.front.mapper;

import com.mihu.stmall.front.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface userMapper {
    @Insert("insert into user (id,username,password,salt,phone,email,realname,sex,birthday,idcard,money,pay_password,reg_time)" +
            "value(#{id},#{username},#{password},#{salt},#{phone},#{email},#{realname},#{sex},#{birthday},#{idcard},#{money},#{payPassword},#{regTime})"
    )
    int insert(User user);
    @Delete("delete from user where id=#{id}")
    int delete(Integer id);
@Update({"<script>",
        "update admin",
        "<set>",
        "<if test='username !=null and username.length>0'> username=#{username},</if>",
        "<if test='password !=null and password.length>0'> password=#{password},</if>",
        "<if test='salt !=null and salt.length>0'> salt=#{salt},</if>",
        "<if test='phone !=null and phone.length>0'> phone=#{phone},</if>",
        "<if test='email !=null and email.length>0'> email=#{email},</if>",
        "<if test='realname !=null and realname.length>0'> realname=#{realname},</if>",
        "<if test='sex !=null and sex.length>0'> sex=#{sex},</if>",
        "<if test='birthday !=null'> birthday=#{birthday},</if>",
        "<if test='idcard !=null and idcard.length>0'> idcard=#{idcard},</if>",
        "<if test='money !=null'> money=#{money},</if>",
        "<if test='payPassword !=null and payPassword.length>0'> pay_password=#{payPassword},</if>",
        "<if test='regTime !=null'> reg_time=#{regTime},</if>",
        "<if test='status !=null'> status=#{status},</if>",
        "where id=#{id}",
        "</set>",
        "</script>",})
    int update(User user);

@Select("select * from where username=#{username}")
    User selectByUserName(String username);
@Select("select * from where id=#{id}")
    User selectById(Integer id);

}
